package cn.zhaoyuening.hnistalumnirecord.service.impl;

import cn.zhaoyuening.hnistalumnirecord.domain.News;
import cn.zhaoyuening.hnistalumnirecord.domain.NewsModule;
import cn.zhaoyuening.hnistalumnirecord.service.NewsModuleService;
import cn.zhaoyuening.hnistalumnirecord.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;

/**
 * Created by zhao on 17-1-17.
 */
@Service
public class NewsModuleServiceImpl extends BaseServiceImpl<NewsModule> implements NewsModuleService {
    private NewsService newsService;
    @Override
    public void cleanModule(int id) {
        NewsModule module = getDao().findById(id);
        for (News news : module.getNewsSet()) {
            newsService.delete(news);
        }
        module.setNewsSet(new HashSet<News>());
        getDao().addOrEdit(module);
    }

    @Autowired
    public void setNewsService(NewsService newsService) {
        this.newsService = newsService;
    }
}
